home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / os2 / e33el2.zip / emacs / 19.33 / lisp / cal-china.el < prev    next >
Lisp/Scheme  |  1996-03-22  |  22KB  |  456 lines

  1. ;;; cal-china.el --- calendar functions for the Chinese calendar.
  2.  
  3. ;; Copyright (C) 1995 Free Software Foundation, Inc.
  4.  
  5. ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
  6. ;; Keywords: calendar
  7. ;; Human-Keywords: Chinese calendar, calendar, holidays, diary
  8.  
  9. ;; This file is part of GNU Emacs.
  10.  
  11. ;; GNU Emacs is free software; you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation; either version 2, or (at your option)
  14. ;; any later version.
  15.  
  16. ;; GNU Emacs is distributed in the hope that it will be useful,
  17. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. ;; GNU General Public License for more details.
  20.  
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with GNU Emacs; see the file COPYING.  If not, write to the
  23. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  24. ;; Boston, MA 02111-1307, USA.
  25.  
  26. ;;; Commentary:
  27.  
  28. ;; This collection of functions implements the features of calendar.el,
  29. ;; diary.el, and holidays.el that deal with the Chinese calendar.  The rules
  30. ;; used for the Chinese calendar are those of Baolin Liu (see L. E. Doggett's
  31. ;; article "Calendars" in the Explanatory Supplement to the Astronomical
  32. ;; Almanac, second edition, 1992) for the calendar as revised at the beginning
  33. ;; of the Qing dynasty in 1644.  The nature of the astronomical calculations
  34. ;; is such that precise calculations cannot be made without great expense in
  35. ;; time, so that the calendars produced may not agree perfectly with published
  36. ;; tables--but no two pairs of published tables agree perfectly either!  Liu's
  37. ;; rules produce a calendar for 2033 which is not accepted by all authorities.
  38. ;; The date of Chinese New Year is correct from 1644-2051.
  39.  
  40. ;; Comments, corrections, and improvements should be sent to
  41. ;;  Edward M. Reingold               Department of Computer Science
  42. ;;  (217) 333-6733                   University of Illinois at Urbana-Champaign
  43. ;;  reingold@cs.uiuc.edu             1304 West Springfield Avenue
  44. ;;                                   Urbana, Illinois 61801
  45.  
  46. ;;; Code:
  47.  
  48. (require 'lunar)
  49.  
  50. (defvar chinese-calendar-celestial-stem
  51.   ["Jia" "Yi" "Bing" "Ding" "Wu" "Ji" "Geng" "Xin" "Ren" "Gui"])
  52.  
  53. (defvar chinese-calendar-terrestrial-branch
  54.   ["Zi" "Chou" "Yin" "Mao" "Chen" "Si" "Wu" "Wei" "Shen" "You" "Xu" "Hai"])
  55.  
  56. (defvar chinese-calendar-time-zone 
  57.   '(if (< year 1928)
  58.        (+ 465 (/ 40.0 60.0))
  59.      480)
  60.   "*Number of minutes difference between local standard time for Chinese
  61. calendar and Coordinated Universal (Greenwich) Time.  Default is for Beijing.
  62. This is an expression in `year' since it changed at 1928-01-01 00:00:00 from
  63. UT+7:45:40 to UT+8.")
  64.  
  65. (defvar chinese-calendar-location-name "Beijing"
  66.   "*Name of location used for calculation of Chinese calendar.")
  67.  
  68. (defvar chinese-calendar-daylight-time-offset 0
  69. ; The correct value is as follows, but the Chinese calendrical
  70. ; authorities do NOT use DST in determining astronomical events:
  71. ;  60
  72.   "*Number of minutes difference between daylight savings and standard time
  73. for Chinese calendar.  Default is for no daylight savings time.")
  74.  
  75. (defvar chinese-calendar-standard-time-zone-name
  76.   '(if (< year 1928)
  77.        "PMT"
  78.      "CST")
  79.   "*Abbreviated name of standard time zone used for Chinese calendar.")
  80.  
  81. (defvar chinese-calendar-daylight-time-zone-name "CDT"
  82.   "*Abbreviated name of daylight-savings time zone used for Chinese calendar.")
  83.  
  84. (defvar chinese-calendar-daylight-savings-starts nil
  85. ; The correct value is as follows, but the Chinese calendrical
  86. ; authorities do NOT use DST in determining astronomical events:
  87. ;  '(cond ((< 1986 year) (calendar-nth-named-day 1 0 4 year 10))
  88. ;         ((= 1986 year) '(5 4 1986))
  89. ;         (t nil))
  90.   "*Sexp giving the date on which daylight savings time starts for Chinese
  91. calendar.  Default is for no daylight savings time.  See documentation of
  92. `calendar-daylight-savings-starts'.")
  93.  
  94. (defvar chinese-calendar-daylight-savings-ends nil
  95. ; The correct value is as follows, but the Chinese calendrical
  96. ; authorities do NOT use DST in determining astronomical events:
  97. ;  '(if (<= 1986 year) (calendar-nth-named-day 1 0 9 year 11))
  98.   "*Sexp giving the date on which daylight savings time ends for Chinese
  99. calendar.  Default is for no daylight savings time.  See documentation of
  100. `calendar-daylight-savings-ends'.")
  101.  
  102. (defvar chinese-calendar-daylight-savings-starts-time 0
  103.   "*Number of minutes after midnight that daylight savings time starts for
  104. Chinese calendar.  Default is for no daylight savings time.")
  105.  
  106. (defvar chinese-calendar-daylight-savings-ends-time 0
  107.   "*Number of minutes after midnight that daylight savings time ends for
  108. Chinese calendar.  Default is for no daylight savings time.")
  109.  
  110. (defun chinese-zodiac-sign-on-or-after (d)
  111.   "Absolute date of first new Zodiac sign on or after absolute date d.
  112. The Zodiac signs begin when the sun's longitude is a multiple of 30 degrees."
  113.  (let* ((year (extract-calendar-year
  114.                 (calendar-gregorian-from-absolute d)))
  115.          (calendar-time-zone (eval chinese-calendar-time-zone))
  116.          (calendar-daylight-time-offset
  117.           chinese-calendar-daylight-time-offset)
  118.          (calendar-standard-time-zone-name
  119.           chinese-calendar-standard-time-zone-name)
  120.          (calendar-daylight-time-zone-name
  121.           chinese-calendar-daylight-time-zone-name)
  122.          (calendar-calendar-daylight-savings-starts
  123.           chinese-calendar-daylight-savings-starts)
  124.          (calendar-daylight-savings-ends
  125.           chinese-calendar-daylight-savings-ends)
  126.          (calendar-daylight-savings-starts-time
  127.           chinese-calendar-daylight-savings-starts-time)
  128.          (calendar-daylight-savings-ends-time
  129.           chinese-calendar-daylight-savings-ends-time))
  130.    (floor
  131.     (calendar-absolute-from-astro
  132.      (solar-date-next-longitude
  133.       (calendar-astro-from-absolute d)
  134.       30)))))
  135.  
  136. (defun chinese-new-moon-on-or-after (d)
  137.   "Absolute date of first new moon on or after absolute date d."
  138.   (let* ((year (extract-calendar-year
  139.                 (calendar-gregorian-from-absolute d)))
  140.          (calendar-time-zone (eval chinese-calendar-time-zone))
  141.          (calendar-daylight-time-offset
  142.           chinese-calendar-daylight-time-offset)
  143.          (calendar-standard-time-zone-name
  144.           chinese-calendar-standard-time-zone-name)
  145.          (calendar-daylight-time-zone-name
  146.           chinese-calendar-daylight-time-zone-name)
  147.          (calendar-calendar-daylight-savings-starts
  148.           chinese-calendar-daylight-savings-starts)
  149.          (calendar-daylight-savings-ends
  150.           chinese-calendar-daylight-savings-ends)
  151.          (calendar-daylight-savings-starts-time
  152.           chinese-calendar-daylight-savings-starts-time)
  153.          (calendar-daylight-savings-ends-time
  154.           chinese-calendar-daylight-savings-ends-time))
  155.     (floor
  156.      (calendar-absolute-from-astro
  157.       (lunar-new-moon-on-or-after
  158.        (calendar-astro-from-absolute d))))))
  159.  
  160. (defvar chinese-year-cache
  161.   '((1989 (12 726110) (1 726139) (2 726169) (3 726198) (4 726227) (5 726257)
  162.           (6 726286) (7 726316) (8 726345) (9 726375) (10 726404) (11 726434))
  163.     (1990 (12 726464) (1 726494) (2 726523) (3 726553) (4 726582) (5 726611)
  164.           (5.5 726641) (6 726670) (7 726699) (8 726729) (9 726758) (10 726788)
  165.           (11 726818))
  166.     (1991 (12 726848) (1 726878) (2 726907) (3 726937) (4 726966) (5 726995)
  167.           (6 727025) (7 727054) (8 727083) (9 727113) (10 727142) (11 727172))
  168.     (1992 (12 727202) (1 727232) (2 727261) (3 727291) (4 727321) (5 727350)
  169.           (6 727379) (7 727409) (8 727438) (9 727467) (10 727497) (11 727526))
  170.     (1993 (12 727556) (1 727586) (2 727615) (3 727645) (3.5 727675) (4 727704)
  171.           (5 727734) (6 727763) (7 727793) (8 727822) (9 727851) (10 727881)
  172.           (11 727910))
  173.     (1994 (12 727940) (1 727969) (2 727999) (3 728029) (4 728059) (5 728088)
  174.           (6 728118)